package com.qibao.toolkit.util;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExpressionUtils {
    /**
     * 抽取变量 ， 不会去重
     *
     * @param src
     * @return
     */
    public static List<String> getAllVariables(String src) {
        List<String> varList = new ArrayList<>();
        if (StringUtils.isEmpty(src)) {
            return varList;
        }
        Pattern pattern = Pattern.compile("(?<=\\{)[^\\}]+");
        Matcher matcher = pattern.matcher(src);
        while (matcher.find()) {
            varList.add(matcher.group());
        }
        return varList;
    }
}
